﻿@{
    ViewBag.Title = "PublishGoods_Step2";
    Layout = "~/Views/Shared/_MainLayout.cshtml";
}
@using MvcMall.Portal.Controllers.Extensions;
@using MvcMall.Portal.Controllers.Stores.ViewModels;
<link href="@Url.Content("~/Content/main.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<style type="text/css">
    .specialCheckBox
    {
        margin-left: 5px;
        padding: 5px;
    }
    
    #specialAttributeTable table
    {
        border: solid 1px #e8eef4;
        border-collapse: collapse;
    }
    
    #specialAttributeTable td
    {
        padding: 5px;
        border: solid 1px #e8eef4;
    }
    
    #specialAttributeTable th
    {
        padding: 5px;
        text-align: center;
        font-weight: normal;
        background-color: #e8eef4;
        border: solid 1px #e8eef4;
    }
</style>
<script type="text/javascript">
    $(function () {
        chkchange();
        $('.specialCheckBox').change(function () { chkchange() });
        GetProvince();
        $('#Province').change(function () { GetCity() });

    });

    function chkchange() {
        var resultArr = new Array();
        $('.specialCheckBox').each(function () {
            if ($(this).attr('checked') == true) {
                resultArr.push($(this).attr('value'));
            }
        });
        $('#specialAttributeTable').hide();
        $("#specialAttributeTable input[type='text']").val("");
        if (resultArr.length != 0) {
            resultArr = Recursive(resultArr);

            $('#specialAttributeTable').show();
            $("#specialAttributeTable tr").hide();
            $("#specialAttributeTableTitle").show();
            for (var i = 0; i < resultArr.length; i++) {
                //alert(resultArr[i]);
                $('#tr' + resultArr[i]).show();
            }
        }
    }

    function Recursive(array) {
        if (array.length > 1) {
            var result = new Array();
            var temp;
            for (var i = 0; i < array.length; i++) {
                //记录当前值                    
                result.push(array[i]);
                //生成子数组                  
                temp = new Array();
                for (var j = 0; j < array.length; j++) {
                    if (j != i) {
                        temp.push(array[j]);
                    }
                }

                //记录递归值  
                if (temp != null) {
                    for (var j = 0; j < temp.length; j++) {
                        result.push(array[i] + temp[j]);
                    }
                }
            }
            return result;
        }
        else if (array.length == 1) {
            return array;
        } return null;
    }

    function GetProvince() {
        $("#Province").empty();
        $("#City").empty();
        $("<option></option>")
                    .val("请选择")
                    .text("请选择")
                    .appendTo($('#Province'));

        var url = "/Ajax/GetChildRegion/1";
        $.getJSON(url, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>")
                    .val(item["Value"])
                    .text(item["Text"])
                    .appendTo($('#Province'));
            });
        });
    }

    function GetCity() {
        $("#City").empty();

        $("<option></option>")
                    .val("请选择")
                    .text("请选择")
                    .appendTo($('#City'));

        var url = "/Ajax/GetChildRegion/" + $('#Province').val();
        $.getJSON(url, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>")
                    .val(item["Value"])
                    .text(item["Text"])
                    .appendTo($('#City'));
            });
        });
    }
</script>
<div class="top_login_nav">
    <div class="top_login_nav_box">
        <ul>
            <li>1.&nbsp;选择商品分类</li>
            <li class="top_login_nav_tag">2.&nbsp;填写商品详细</li>
            <li>3.&nbsp;发布商品成功</li>
        </ul>
    </div>
</div>
<div class="wrap">
    @using (Html.BeginForm("PublishGoods_Step2", "Stores", FormMethod.Post, new { @target = "publish" }))
    {
        <div class="entry_box">
            <div class="enter_title">
                <span class="enter_title_blue">填写商品基本信息</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="red">*</span>&nbsp;表示该项必填</div>
            <table class="enter_tab" width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr height="30">
                    <td colspan="2" class="entry_tab_title">
                        1、商品基本信息
                    </td>
                </tr>
                <tr height="30">
                    @Html.Hidden("CatId", ViewData["CatId"])
                    <td class="entry_tab_td1">
                        <span class="red">*</span>&nbsp;商品类型：
                    </td>
                    <td class="entry_tab_td2">
                        @foreach (var item in (ViewData["GoodsTypeList"] as IEnumerable<SelectListItem>))
                        {
                            @Html.RadioButton("GoodsType", item.Value, item.Selected)<text>@item.Text</text>
                        }
                    </td>
                </tr>
                <tr>
                    <td class="entry_tab_td1">
                        商品属性：
                    </td>
                    <td class="entry_tab_td2" style="padding: 10px 0 10px 0;">
                        <table bgcolor="#f0f0f0" width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr height="30">
                                <td style="padding: 10px 10px 0 10px;" colspan="2">
                                    <div class="tips">
                                        <img align="absMiddle" src="/content/images/lightbulb.gif" />&nbsp;<span class="red">温馨提示：</span>请准确填写商品属性，否则会导致商品下架，影响您的正常销售。</div>
                                </td>
                            </tr>
                            @foreach (var item in (ViewData["NormalAttribute"] as IList<GoodsCatAttributeModel>))
                            {
                                <tr height="30">
                                    <td class="entry_tab_td1">
                                        @if (item.AttrType == MvcMall.Core.Enums.AttrType.多个属性必选 || item.AttrType == MvcMall.Core.Enums.AttrType.唯一属性必选)
                                        {
                                            <span class="red">*</span>
                                        }
                                        @item.AttrName
                                    </td>
                                    <td class="entry_tab_td2">
                                        @Html.GoodsCatAttribute(item, null)
                                    </td>
                                </tr>
                            }
                        </table>
                    </td>
                </tr>
                @foreach (var item in ViewData["SpecialAttribute"] as IList<GoodsCatAttributeModel>)
                {
                    <tr height="30">
                        <td class="entry_tab_td1">
                            @item.AttrName：
                        </td>
                        <td class="entry_tab_td2">
                            @Html.SpecialAttribute(item)
                        </td>
                    </tr>
                }
                <tr height="30">
                    <td class="entry_tab_td1">
                    </td>
                    <td class="entry_tab_td2">
                        @Html.SpecialAttributeTable(ViewData["SpecialAttribute"] as IList<GoodsCatAttributeModel>)
                    </td>
                </tr>
                <tr height="30">
                    <td class="entry_tab_td1">
                        <span class="red">*</span>&nbsp;商品名称：
                    </td>
                    <td class="entry_tab_td2">
                        @Html.TextBox("GoodsName", string.Empty, new { @style = " width:400px;" })
                    </td>
                </tr>
                <tr height="40">
                    <td colspan="2" class="entry_tab_title">
                        2、商品物流信息
                    </td>
                </tr>
                <tr>
                    <td class="entry_tab_td1">
                        <span class="red">*</span>&nbsp;商品所在地：
                    </td>
                    <td class="entry_tab_td2">
                        <select id="Province" nam="Province">
                        </select>
                        <select id="City" name="City">
                        </select>
                    </td>
                </tr>
                <tr height="30">
                    <td class="entry_tab_td1">
                        <span class="red">*</span>&nbsp;运费：
                    </td>
                    <td class="entry_tab_td2">
                        @foreach (var item in ViewData["FreightType"] as List<SelectListItem>)
                        {
                            @Html.RadioButton("FreightType", item.Value)<text>@item.Text</text>                               
                        }
                    </td>
                </tr>
            </table>
        </div>
        <div class="entry_box_btn">
            <input style="background-image: url('/content/images/btn7.gif'); margin: 0px; padding: 0px;
                border: 0; width: 219px; height: 45px;" value=" " type="submit" />
        </div>
    }
    <iframe id="publish" name="publish" width="100%" frameborder="0" scrolling="no">
    </iframe>
</div>
